package objects;

import java.util.HashMap;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.tiled.TiledObject;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;

public class AbstractObject extends BodyDef {

	TiledObject object;
	Texture texture;
	Sprite sprite;
	PolygonShape shape;
	FixtureDef fixtureDef;
	public static final float PIXELS_PER_METER = 96.0f;
	SpriteBatch spriteBatch;
	Body body;
	World world;

	public SpriteBatch getSpriteBatch() {

		return spriteBatch;
	}

	public FixtureDef getFixtureDef() {

		return fixtureDef;
	}

	public Sprite getSprite() {

		return sprite;

	}

	public String getName() {

		return object.name;
	}

	public String getObjectType() {

		return object.type;
	}

	public HashMap getProperties() {

		return object.properties;
	}

	public void setSprite(Sprite _sprite){
		
		sprite = _sprite;
	}
	public void removeSprite(){
		sprite = null;
	}
	
	public int getWidth() {
		return object.width;
	}

	public int getHeight() {
		return object.height;
	}

	public int getX() {
		return object.x;
	}

	public int getY() {
		return object.y;
	}

	public int getGID() {
		return object.gid;

	}

	public void setBody(Body _body) {
		body = _body;

	}

	public Body getBody() {
		return body;
	}

	public void renderObject(Camera _camera, SpriteBatch _spritebatch) {
		if (body.isActive()) {
			// System.out.println("object render");
			// spriteBatch.setProjectionMatrix(_camera.combined);
			// spriteBatch.begin();

			sprite.setPosition(
					PIXELS_PER_METER * body.getPosition().x - sprite.getWidth()
							/ 2, PIXELS_PER_METER * body.getPosition().y
							- sprite.getHeight() / 2);
			sprite.draw(_spritebatch);
			// spriteBatch.end();
			// System.out.println("item pos: " + body.getPosition());
		}
	}
}
